#include <stdio.h>

int Puissance4(int tab[7][6])
{
   int i,j,k,count=1,gagnant;
   for ( i=0 ; i < 7 ; i++ ) {
      for ( j=0 ; j < 6 ; j++ ) {
         if ( tab[i][j] != 0 ) {
            for ( k=1 ; k<4 ; k++ )
               if ( i<4 )
	          if (tab[i][j] == tab[i+k][j]) count++;
	    if (count==4) return tab[i][j];
	    count = 1;

            for ( k=1 ; k<4 ; k++ )
               if ( j<3 )
	          if (tab[i][j] == tab[i][j+k]) count++;
	    if (count==4) return tab[i][j];
	    count = 1;

            for ( k=1 ; k<4 ; k++ )
	       if ( i<4 && j<3 )
	          if (tab[i][j] == tab[i+k][j+k]) count++;
	    if (count==4) return tab[i][j];
	    count = 1;

            for ( k=1 ; k<4 ; k++ )
	       if ( i>2 && j<3 )
	          if (tab[i][j] == tab[i-k][j+k]) count++;
	    if (count==4) return tab[i][j];
	    count = 1;
         }
      }
   }
   return 0;
}

int main()
{
   int i,j;
   int tab[7][6];
   int gagnant;
   char c;
   for (i = 0; i < 6; i++)
      for (j = 0; j< 7; j++)
      {
         do {
            scanf("%c", &c);
         } while ((c == '\n') || (c == '\r'));
         tab[j][i] = c - '0';
      }
   gagnant = Puissance4(tab);
   printf("%d\n", gagnant);
   return 0;
}

